/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ru.miit.elearning.hibernate.dto.beans;

import java.io.Serializable;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import ru.miit.elearning.hibernate.dto.UserData;
import ru.miit.elearning.hibernate.dto.WorkItem;

/**
 *
 * @author Cyclone
 */
public class CourseBean implements Serializable {

    private UserData userData = null;
    private WorkItem workItem = null;
    private List<WorkItem> labWorkItemList = null;
    private List<StudentWithLabs> studentWithLabsList = null;

    public List<StudentWithLabs> getStudentWithLabsList() {
        return studentWithLabsList;
    }

    public void setStudentWithLabsList(List<StudentWithLabs> studentWithLabsList) {
        this.studentWithLabsList = studentWithLabsList;
    }

    public List<WorkItem> getLabWorkItemList() {
        return labWorkItemList;
        /*
        Object[] objectWorkItems = labWorkItemList.toArray();
        WorkItem[] workItems = new WorkItem[objectWorkItems.length];
        for (int i = 0; i < objectWorkItems.length; i++) {
        workItems[i] = (WorkItem)objectWorkItems[i];
        }

        Arrays.sort(workItems, new Comparator<WorkItem>() {
        public int compare(WorkItem o1, WorkItem o2) {
        if(o1 == null || o2 == null) {
        System.err.println("CourseBean:getLabWorkItemList().compare(): o1 == null || o2 == null");
        return 0;
        }
        if(o1.getCurriculumLevel() == null || o2.getCurriculumLevel() == null) {
        System.err.println("CourseBean:getLabWorkItemList().compare(): o1.getCurriculumLevel() == null || o2.getCurriculumLevel() == null");
        return 0;
        }
        if(o1.getCurriculumLevel().getNumeral() == null) {
        return 1;
        }
        if(o2.getCurriculumLevel().getNumeral() == null) {
        return -1;
        }
        return o1.getCurriculumLevel().getNumeral().compareTo(o2.getCurriculumLevel().getNumeral());
        }
        });
        return Arrays.asList(workItems);
         */
    }

    public void setLabWorkItemList(List<WorkItem> labWorkItemList) {
        //this.labWorkItemList = labWorkItemList;
        Collections.sort(labWorkItemList, new Comparator<WorkItem>() {

            public int compare(WorkItem o1, WorkItem o2) {
                return o1.getCurriculumLevel().getNumeral() == null ? 1
                        : (o2.getCurriculumLevel().getNumeral() == null ? -1
                        : (o1.getCurriculumLevel().getNumeral().compareTo(o2.getCurriculumLevel().getNumeral())));
            }
        });
        this.labWorkItemList = labWorkItemList;
    }

    public UserData getUserData() {
        return userData;
    }

    public void setUserData(UserData userData) {
        this.userData = userData;
    }

    public WorkItem getWorkItem() {
        return workItem;
    }

    public void setWorkItem(WorkItem workItem) {
        this.workItem = workItem;
    }
}
